package com.xiao.javatest.annotation;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class MyPoccesser {

	
	public static String getTableName(Class<?> clazz){
		Field[] fields = clazz.getDeclaredFields();
		String tableName = "";
			MyTable mytable = clazz.getAnnotation(MyTable.class);
			if(mytable==null){
				return "";
			}
			tableName = mytable.name();
			if("".equals(tableName) || tableName==""){
				tableName = clazz.getName();
				tableName = clazz.getSimpleName();
			}
		return tableName;
	}
	
	public static Map<String,String> getColumnProperty(Class<?> clazz){
		Field[] fields = clazz.getDeclaredFields();
		Method[] methods = clazz.getDeclaredMethods();
		
		String columnName = "";
		String columnType = "String";
		Map<String,String> map = new HashMap<String, String>();
		
		for(Field field :fields){
			MyColumn myColumn = field.getAnnotation(MyColumn.class);
			if(myColumn==null){
				String setField = ("set"+field.getName()).toLowerCase();

				for(Method m : methods){
					myColumn = m.getAnnotation(MyColumn.class);
					String setMethod = m.getName().toLowerCase();
					
				}
			}
			columnName = myColumn.name();
			columnType = myColumn.type();
			
			if(columnName==""){
				columnName = field.getName();
			}
			if(columnType==""){
				columnType = "String";
			}
			map.put(columnName, columnType);
		}
		
		return map;
	}
	
//	public static String getColumnType(Class<?> clazz){
//		Field[] fields = clazz.getDeclaredFields();
//		String columnType = "String";
//		for(Field field :fields){
//			MyColumn myColumn = field.getAnnotation(MyColumn.class);
//			
//			
//		}
//		return columnType;
//	}
}
